/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.com.pps.web.bean.course;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;
import vn.com.pps.web.common.component.table.LazyCacheModel;
import vn.com.pps.web.ui.TeacherAttendanceTableItem;

/**
 *
 * @author Dai
 */
public class LessonRecordBean extends LazyCacheModel implements Serializable{

    private int courseID;
    int rowCount=0;
    private ArrayList<TeacherAttendanceTableItem> teacherAttendanceTableItem;

            
    @Override
    public void sort(String pm_column, boolean pm_ascending) {
         Comparator<TeacherAttendanceTableItem> bc = null;
        if (pm_ascending) {
            bc = new BeanComparator(pm_column);
        } else {
            bc = new BeanComparator(pm_column, new ReverseComparator(new ComparableComparator()));
        }
        Collections.sort(getPageItems(), bc);
    }

    @Override
    public void loadData() {
        rowCount= getServiceLocator().getCourseService().getTakenRecordCount(courseID);
        teacherAttendanceTableItem = getServiceLocator().getCourseService().getTakenRecordsByCourse(getTargetPage(), getMaximumPageSize(),courseID);
        setPageItems(teacherAttendanceTableItem);
        setRowCount(rowCount);
    }

    public int getCourseID() {
        return courseID;
    }

    public void setCourseID(int courseID) {
        this.courseID = courseID;
    }
    
    
    
}
